package com.franklin.plugins.common.collection;

import java.util.Iterator;

class CollectionPrint {

    static <E> String toString(Iterable<E> iterable){
        Iterator<E> it = iterable.iterator();

        if (! it.hasNext())
            return "[]";

        StringBuilder sb = new StringBuilder();
        sb.append('[').append('\n');
        for (;;) {
            E e = it.next();
            sb.append("   ");
            sb.append(e == iterable ? "(this Collection)" : e);
            if (! it.hasNext())
                return sb.append('\n').append(']').toString();
            sb.append(',').append('\n');
        }
    }

}
